<?php
     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     header("content-type: application/x-javascript; charset=tis-620");
   	 include_once('connection/connection.php');
   	 $data=$_GET['data'];
     $val=$_GET['val'];
	 
	 if($data=='district')
	 {
          echo "<select name='district' id='district' class='txt' onChange=\"changeBlock('block',this.value);change_factor('factor',this.value);changeTehsil('tehsil',this.value)\">\n";
          echo "<option value='0'>==== District ====</option>\n";
          $result=mysql_query("select DISTINCT district_id, district_name from tbl_lookup_location order by district_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }    
	 }
	 if($data=='factor')
	 {		
         	$val2=$val;
         	$val = substr($val,0,10); 
			$qr="SELECT population_factor FROM tbl_lookup_pop_factor WHERE district_id = '$val'";
			$res=mysql_query($qr);
			$row=mysql_fetch_array($res);
			$factor=$row['population_factor'];
			?>    
			<input type="hidden"  name="factor1" id="factor1" value="<?php echo $factor;?>" class="txt5" size=20 style="color:#FF0000">
         	<?php 
		}
	 	if($data=='block')
	 	{		
	 		echo "<select name='block' class='txt' onChange=\"changePanchayat('panchayat',this.value)\" >\n";
         	echo "<option value='0'>=====Block====</option>\n";
         	$val2=$val;
         	$val = substr($val,0,10);                            
         	$result=mysql_query("SELECT DISTINCT block_id, block_name from tbl_lookup_location where district_id='$val' order by block_name");
         	while(list($id, $name)=mysql_fetch_array($result))
		 	{       
				 echo "<option value=\"$id\">$name</option> \n";
         	}	 	
		}
		if($data=='tehsil')
		{
		 	echo "<select name='tehsil' class='txt'>\n
         	<option value='0'>=====Tehsil====</option>\n";
		 	$result1=mysql_query("SELECT DISTINCT census_subdistrict_code,census_subdistrict_name from tbl_lookup_location where district_id='$val' order by census_subdistrict_name");
		 	while(list($id1, $name1)=mysql_fetch_array($result1))
		 	{       
              	echo "<option value=\"$id1\">$name1</option> \n";
         	}	 	
		}
	 if ($data=='panchayat') 
	 {
		  $val2=$val;
		  $val = substr($val,0,10);
          echo "<select name='panchayat' class='txt' onChange=\"changeVillage('village',this.value)\">\n";
          echo "<option value='0'>=Gram panchayat=</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT panchayat_id, panchayat_name from tbl_lookup_location where block_id='$val' order by panchayat_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option>\n" ;
          }
	  } 
	  if ($data=='village') 
	  {
		 $val2=$val;
		 $val = substr($val,0,10);
          echo "<select  name='village' class='txt' onChange=\"changeHabit('habit',this.value);changeCensusCode('cvc',this.value);changeFormId(this.form,'form_id',this.value);changePopulation('population_benefited',this.value);changePrePopulation('present_population',this.value)\" >\n";
          echo "<option value='0'>=====Village====</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT village_id, village_name from tbl_lookup_location where panchayat_id='$val' order by village_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }
		}
		 if ($data =='cvc') 
	  	{
		   $val2=$val;
		   $val = substr($val,0,10);
		   $result=mysql_query("SELECT DISTINCT census_village_code from tbl_lookup_location where village_id='$val' order by village_name");
         	while(list($id1)=mysql_fetch_array($result))
		 	{ ?>      
              <input type="text" name="cvc" value="<?php echo $id1;?>" readonly class=txt size=20 style="color:#FF0000">
			  
         	<?php }
		 }
		 
		if ($data =='population_benefited') 
	  	{
			$val2=$val;
			$val = substr($val,0,10);
			$qr="SELECT SUM(total_population) AS total_population from tbl_lookup_location where village_id='$val' order by village_name";
			$res=mysql_query($qr);
			$row=mysql_fetch_array($res);
			$id2=$row['total_population'];
		   ?>      
		   <input type="text" name="population_benefited1" id="population_benefited1" value="<?php echo $id2;?>" readonly class="txt5" size="20" style="color:#FF0000">
         <?php 
		 }
		 if ($data =='present_population') 
	  	{
			$val2=$val;
			$val = substr($val,0,10); ?>
         <input type="text" name="present_population1" id="present_population1" value="" readonly class="txt5" size="20" style="color:#FF0000" />
         <?php 
		 }
		 
		 if ($data =='form_id') 
	  	 {
		 	$val2=$val;
			$val = substr($val,0,10);
			$dist=$_GET['dist'];
	 	 	//echo $dist;
			$qid="UPDATE sequence SET id=LAST_INSERT_ID(id+1)";
			$rid = mysql_query($qid);
			$qryId="select id from sequence";
			//echo $qryId;
			$recId=mysql_query($qryId);
			$rowId=mysql_fetch_array($recId);
			$id=$rowId['id'];
			$form_id = substr($dist,0,4);
			$form_id = "Q2" . "-" . $form_id . "-"  . $id;
			?>
			<input type="text" style="color:#FF0000" name="form_id" value="<?php echo $form_id; ?>" readonly class=txt size=20>
			<input type="hidden" style="color:#FF0000" name="id" value="<?php echo $id; ?>" readonly class=txt size=20>
		<?php } 
	  if ($data=='habit') 
	  {
		 $val2=$val;
		 $val = substr($val,0,10);
		 $q="SELECT DISTINCT habitation_code, habitation_name from tbl_lookup_location where village_id='$val' order by habitation_code";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query($q);
		  $num_habit = mysql_num_rows($result);
		  $i=1;
		  while(list($id, $name)=mysql_fetch_array($result))
		  {
		  ?>
		  <table width="95%">
			<tr>
			<td width="20%" align="center"><font id=habit_code>
					
			  <input type="text" name="habit_code<?php echo $i;?>" id="habit_code<?php echo $i;?> "value="<?php echo $id;?>" size="20" class="txt5" readonly></font></td>
				<td width="26%" align="center"><font id=habit>
			  <input type="text" name="habit_name<?php echo $i;?>" id="habit_name<?php echo $i;?>" value="<?php echo ucwords(strtolower($name));?>" class="txt7" readonly></font></td>
			  <td align="center" width="19%"><input type="text" name="type_mh_oh<?php echo $i;?>" id="type_mh_oh<?php echo $i;?>" value="<?php if($i==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>
				<td width="21%" align="center"><font id=habit_code>
					
			  <input type="text" name="hp_no<?php echo $i;?>" id="hp_no<?php echo $i;?>" value="0" size="20" class="txt5" onBlur="numeric(this)"></font></td>
				<td width="14%" align="center">
			  <input type="text" name="sp_no<?php echo $i;?>" id="sp_no<?php echo $i;?>" size="20" class="txt5" onBlur="numeric(this)" value="0"></td>
			</tr></table>
		<?php
		$i++;
          }  
		  
		  echo "<input type='hidden' name='habit_count' id='habit_count' value=".$num_habit."></table>"; 
    }
?>